﻿using FastMvc.Crud;
using JQ.SAAS.Entity;
using JQ.SAAS.DTO.SysMenus;
using System;
using System.Collections.Generic;
using System.Text;
using FastMvc.Repositories;
using Microsoft.AspNetCore.Mvc;
using FastMvc.Auth;
using FastMvc.Models;
using System.Threading.Tasks;
using JQ.SAAS.IService;

namespace JQ.SAAS.WebServer.Controllers
{
    /// <summary>
    /// 系统菜单管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [PermissionCheck("Admin.Sys.Menus","系统菜单管理")]
    public class SysMenusController : CrudController<sys_menu,SysMenusDto,string,SysMenusListRequestDto,SysMenusCreateDto, SysMenusUpdateDto>
    {
        private ISysMenusService sysMenusService;
        public SysMenusController(ISysMenusService service)
            : base(service)
        {
            sysMenusService = service;
        }

        /// <summary>
        /// 仅有查询数结构的，不支持普通的列表查询
        /// </summary>
        /// <param name="listPageRequest"></param>
        /// <returns></returns>
        [NonAction] // 通过这种方法，来隐藏父Controller中已经定义的Action
        public override Task<BaseResult<ListData<SysMenusDto>>> QueryList([FromQuery] SysMenusListRequestDto listPageRequest)
        {
            throw new FastMvc.Exceptions.ApiException("未实现的方法！");
        }

        /// <summary>
        /// 查询当前菜单树
        /// </summary>
        /// <returns></returns>
        [HttpGet("")]
        public async Task<BaseResult<List<SysMenusDto>>> GetMenuTree()
        {
            var datas = await sysMenusService.GetTreeList();

            return await SetResultNotNull(datas);
        }
    }
}
